#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>

int main()
{
	int i, n, x, t, j;
	char a[10000];
	scanf("%d", &n);
	getchar();
	for (i = 0; i < n; i++) {
		gets(a);
		x = strlen(a);
		t = 0;
		if (a[0] != ' ') t++;
		for (j = 0; j < x; j++) {
			if (a[j] == ' ' && a[j + 1] != ' ' && a[j + 1] != '\0') t++;
		}
		printf("%d\n", t);
	}

	return 0;
}
//1091